<script setup lang="ts">
import type { ConcurrentNode } from './type'
import type { Ref } from 'vue'
import type { ErrorInfo } from './type'
import Node from './Node.vue'

const props = defineProps<{
  node: ConcurrentNode
}>()

const { nodesError } = inject<{
  nodesError: Ref<Recordable<ErrorInfo[]>>
}>('flowDesign', { nodesError: ref({}) })

// 拦截activeNode事件，防止弹出抽屉
const handleActiveNode = () => {
  // 不执行任何操作，阻止事件冒泡
}

watchEffect(() => {
  const errors: ErrorInfo[] = []
  const { id, name, next } = props.node
  
  // 检查分支下是否有节点
  if (!next) {
    errors.push({ id: id, name: name, message: '分支下节点为空' })
  }
  
  // 记录错误
  if (errors.length > 0) {
    nodesError.value[id] = errors
  } else {
    delete nodesError.value[id]
  }
})
</script>

<template>
  <div class="branch-node">
    <Node v-bind="$attrs" icon="el:Share" :node="node" @activeNode="handleActiveNode">
      <el-text>{{ node.name }}</el-text>
      <slot name="append" />
    </Node>
  </div>
</template>

<style scoped lang="scss">
.branch-node {
  :deep(.node-box) {
    margin: 60px 40px 0;
  }
}
</style> 